import requests
import json
import pandas as pd

api_key = 'b952a5c5-dbd9-4671-8a69-bb5949aa8190'
status = 'inactive,active,untracked'
url = f'https://pro-api.coinmarketcap.com/v1/cryptocurrency/map'
start = 1
page_size = 5000
all_df_list = []
while True:
    params = {"listing_status": status,
              "start": start,
              "limit": page_size,
              "sort": "id",
              'aux': "platform,first_historical_data,last_historical_data,is_active,status",
              }
    header = {
        'X-CMC_PRO_API_KEY': api_key}
    a = requests.get(url, params=params, headers=header, timeout=30)
    res = json.loads(a.text)
    df = pd.DataFrame(res['data'])
    all_df_list.append(df)
    if len(df) < page_size:
        break
    else:
        start = start + page_size
all_df = pd.concat(all_df_list, axis=0, ignore_index=True)
all_df.to_csv("G:/data/coinmarketcap/all_coin_list.csv", index=False)
